<?php require_once('../Connections/miportal.php');?>
<?php
mysql_query("SET NAMES 'utf8'");?>
<?php

if (!function_exists("GetSQLValueString")){
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6){
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue): mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}
?>
<?php
// *** Validate request to login to this site.
if (!isset($_SESSION)) {
  session_start();
}

$loginFormAction = $_SERVER['PHP_SELF'];
if (isset($_GET['accesscheck'])) {
  $_SESSION['PrevUrl'] = $_GET['accesscheck'];
}

if (isset($_POST['usuario'])) {
  $loginUsername=$_POST['usuario'];
  $password=$_POST['password'];
  
  $MM_fldUserAuthorization = "tp_perfil";
  $MM_redirectLoginSuccess = NULL;
  $MM_redirectLoginFailed = "login.php";
  $MM_redirecttoReferrer = false;
  mysql_select_db($database_miportal, $miportal);
  	
  $LoginRS__query=sprintf("SELECT nmb_nombres, nmb_apaterno, nmb_amaterno, nmb_titulo, aut_nom_usuario, aut_contador, cat2_usuario.tp_perfil, cat2_usuario.id_target, cat2_usuario.aut_target, cat2_usuario.nmb_target, tp_programa, id_cat_convocatoria FROM acs_control_usuario LEFT JOIN cat2_usuario ON(acs_control_usuario.id_usuario=cat2_usuario.id_usuario) WHERE aut_nom_usuario=%s AND aut_passwd=%s",
  GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text"));    
  $LoginRS = mysql_query($LoginRS__query, $miportal) or die(mysql_error());
  $row_LoginRs =  mysql_fetch_assoc($LoginRS);   
  $rqUpdateSql= mysql_query($updateSql, $miportal);
  
  
  //DATOS DE LA CUENTA DE USUARIO     
	$_SESSION['MM_UserId'] = $row_LoginRs['id_usuario'];
	$_SESSION['MM_UsName'] = $row_LoginRs['nmb_titulo']." ".$row_LoginRs['nmb_nombres']." ".$row_LoginRs['nmb_apaterno']." ".$row_LoginRs['nmb_amaterno'];
	$_SESSION['MM_Perfil']=$row_LoginRs['tp_perfil'];
	$_SESSION['MM_id_target']=$row_LoginRs['id_target'];
	$_SESSION['MM_aut_target']=$row_LoginRs['aut_target'];
	$_SESSION['MM_nmb_target']=$row_LoginRs['nmb_target'];
	$_SESSION['MM_tp_programa']=$row_LoginRs['tp_programa'];
	$_SESSION['MM_id_cat_convocatoria']=$row_LoginRs['id_cat_convocatoria'];
	$_SESSION['convocatoria']=($row_LoginRs['id_cat_convocatoria']);
	$_SESSION['MM_id_candidato']="";
	$_SESSION['MM_id_empresa']="";
	$loginFoundUser = mysql_num_rows($LoginRS);
  if ($loginFoundUser) {
    
    $loginStrGroup  = mysql_result($LoginRS,0,'tp_perfil');
    
	if (PHP_VERSION >= 5.1) {session_regenerate_id(true);} else {session_regenerate_id();}
    //declare two session variables and assign them
    $_SESSION['MM_Username'] = $loginUsername;
    $_SESSION['MM_UserGroup'] = $loginStrGroup;	      

    if (isset($_SESSION['PrevUrl']) && false) {
      $MM_redirectLoginSuccess = $_SESSION['PrevUrl'];	
    }
		if($_SESSION['MM_Perfil']=="RIV"){ 
		$MM_redirectLoginSuccess='riv.php';
		}else if($_SESSION['MM_Perfil']=="ROV"){
		$MM_redirectLoginSuccess='login.php';
		}else if($_SESSION['MM_Perfil']=="DVA"){
		$MM_redirectLoginSuccess='dva.php';
		}else if($_SESSION['MM_Perfil']=="DIR_DVA"){
		$MM_redirectLoginSuccess='dir_dva.php';
		}else  if($_SESSION['MM_Perfil']=="DVE"){
		$MM_redirectLoginSuccess='dve.php';
		}else if($_SESSION['MM_Perfil']=="DIR_DVE"){
		$MM_redirectLoginSuccess='dir_dve.php';
		}else  if($_SESSION['MM_Perfil']=="JURIDICO"){
		$MM_redirectLoginSuccess='juridico.php';
		}else  if($_SESSION['MM_Perfil']=="COA"){
		$MM_redirectLoginSuccess='coa.php';
		}else  if($_SESSION['MM_Perfil']=="DIR_COA"){
		$MM_redirectLoginSuccess='dir_coa.php';
		}else if($_SESSION['MM_Perfil']=="EMPRESA"){
		$MM_redirectLoginSuccess='empresa.php';
		}else if($_SESSION['MM_Perfil']=="REPORTE"){
		$MM_redirectLoginSuccess='reporte.php';
		}else if($_SESSION['MM_Perfil']=="APOYO"){
		$MM_redirectLoginSuccess='apoyo.php';
		}
		else{
			$MM_redirectLoginSuccess='login.php';
		}
    header("Location: " . $MM_redirectLoginSuccess);
  }
  else {
    header("Location: ". $MM_redirectLoginFailed);
  }
}
?>




<!DOCTYPE html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximun-scale=1">
<title>FUNDACIÓN EDUCACIÓN SUPERIOR-EMPRESA</title>
<!--Hoja de estilo principal-->
<link href="../css/styletd2.css" rel="stylesheet" type="text/css">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<link rel="shortcut icon" href="stylesheet/img/devil-icon.png"> 
<link rel="stylesheet" type="text/css" href="../css/mos-style.css"><!--Pemanggilan gambar favicon-->
 <!--pemanggilan file css-->
<script src="../SpryAssets/SpryValidationTextField.js" type="text/javascript"></script>
<link href="../SpryAssets/SpryValidationTextField.css" rel="stylesheet" type="text/css">
</head>
<body>

<div id="background">
</div>
 
 <header>
    <div class="img_header_logo"></div>
    <span class="img_header_logo"><a href="http://fese.org.mx"><img src="../images/fese/FESE_home_logo.png"  height="90" alt="FESE" align="bottom" /></a></span>
    
  <!--Menú principal de navegación-->

</header>
                        
<center>

<div id="boxcontainer">

<strong><p style="font-size:16px; color:#399;">Bienvenido a Mi portal FESE, para gestionar tu cuenta ingresa tu nombre de usuario y contraseña.</p></br><p> Si tienes pregunta o sugerencia no dudes en comunicarte, con gusto te atenderemos.  </p></strong> 
				   
    <div id="loginForm">
		<div class="headLoginForm">	Acceso</div>
		<div class="fieldLogin">
		<form ACTION="<?php echo $loginFormAction; ?>" method="POST" id="formLogin" >
			<label>USUARIO</label><br>
			<span id="spryUsuario">
			<input name="usuario" type="text" class="login" id="usuario">
			<span class="textfieldRequiredMsg">*</span></span><br>
			<label>CONTRASEÑA</label><br>
			<span id="spryPassword">
			<input name="password" type="password" class="login" id="password">
			<span class="textfieldRequiredMsg">*</span></span><br>
			<input type="submit" class="button" value="Acceder">
			<input name="idUsuario" type="hidden" value="<?php if(isset($row_rsProyecto['id_usuario']))?>">
		</form>
		</div>
           
           <script type="text/javascript">
           var sprytextfield1 = new Spry.Widget.ValidationTextField("spryUsuario", "none", {validateOn:["blur"]});
           var sprytextfield2 = new Spry.Widget.ValidationTextField("spryPassword", "none", {validateOn:["blur"]});
           </script>        
                   
		</div>
 </div> 
   
 </center>
  

 
</body>
</html>